package com.lancoo.ccas53.arrangecourse.rulecheck;

import cn.hutool.core.util.StrUtil;
import com.lancoo.ccas53.arrangecourse.entities.ClassHour;
import com.lancoo.ccas53.arrangecourse.entities.TeachingClassUnit;
import com.lancoo.ccas53.arrangecourse.entities.TimeslotRoom;

import java.util.LinkedList;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * @Description 排课规则对象，需要进行增强，即装饰的对象
 * @Author Fortysun
 * @Date 2023/9/5 16:28
 **/
public class ScheduleRule implements RuleService {
    /**
     * 检测是否适合分配：
     * 判断待分配的教室课时分组，是否满足教学班设置的优先排规则
     * @param teachingClassUnit 教学班排课单元
     * @param continuousList 连上的教室课时分组信息列表
     * @param classHourMap 课表课时map
     * @return
     */
    @Override
    public Boolean isSuitable(TeachingClassUnit teachingClassUnit,
                              LinkedList<TimeslotRoom> continuousList,
                              ConcurrentHashMap<String, CopyOnWriteArrayList<ClassHour>> classHourMap) {
        //取这个教室的容量，与教学班的人数进行比较，能坐下才进行分配
        //因为涉及到多班级分配，所以分组列表都需要判断
        for (TimeslotRoom timeslotRoom : continuousList) {
            if (teachingClassUnit.getRoomId() != null
                    && StrUtil.isNotEmpty(teachingClassUnit.getPhyClassId())
                    && teachingClassUnit.getPhyClassId().contains(",")
//                    && teachingClassUnit.getPhyClassId().split(",").length > 1
            ){
                return true;
            }
            if (timeslotRoom.getCapacity() < teachingClassUnit.getTeachingClassSize()) {
                return false;
            }
        }
        return true;
    }
}
